﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Net;
using HtmlAgilityPack;
using System.Collections;

namespace Bai2
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]

    public class Service1 : System.Web.Services.WebService
    {
        RepositoryCustomer repo = new RepositoryCustomer();
        Support s = new Support();
        [WebMethod]
        public DataSet CustomerAll()
        {
            return repo.GetAll();
        }
        [WebMethod]
        public string MD5(string text)
        {
            return s.getMD5(text);
        }
        [WebMethod]
        public string MD52(string text)
        {
            return s.getMd5Hash(text);
        }
        [WebMethod]
        public string SHA1(string text)
        {
            return s.getSHA1(text);
        }

        [WebMethod]
        public string SHA12(string text)
        {
            return s.getSha1Hash(text);
        }
        [WebMethod]
        public byte[] Image2Byte(string text)
        {
            return s.Image2Byte(text);
        }

        
        [WebMethod]
        public int Create(Customer c)
        {
            return repo.Create(c);
        }

        //[WebMethod(Description = "This is Html Scraping")]
        [WebMethod]
        public List<string> GetName()
        {
            List<string> list = new List<string>();
            string html = "";

            using (WebClient client = new WebClient())
            {
                html = System.Text.Encoding.UTF8.GetString(client.DownloadData("http://localhost/Student"));
            }

            HtmlDocument doc = new HtmlDocument();
            doc.LoadHtml(html);
            //var root = doc.DocumentNode.Descendants("td");
            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//table[1]/tr[position()>1]/td[3]"))
            {
                list.Add(node.InnerHtml);
            }

            return list;
        }
        [WebMethod]
        public ArrayList GetCode()
        {
            ArrayList list = new ArrayList();
            HtmlWeb web = new HtmlWeb();
            HtmlDocument doc = web.Load("http://localhost/Student");

            foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//table[1]/tr[position()>1]/td[2]"))
            {
                list.Add(node.InnerHtml);
            }

            return list;
        }
    }
}